<?php
namespace Admin\Model;
use Think\Model;

class MenuModel extends Model{

    const STATUS=1;
    const PARENT_ID=0;
    /**
     * 公共构造方法
     */
    public function __construct()
    {

        parent::__construct();
        $this->MenuModel = new Model();
        $this->connection = $this->db(1,"mysql://root:123456@localhost:3306/mmy2");
    }


    /**
     *  function select
     * @return mixed
     */
    public function getUserList()
    {
        $data =  $this->user->where('status = 1')->select();
        return $data;
    }

    /**
     * 获取导航方法
     * @author mmy
     */
    public function getMenuList($parent_id =0,&$result = array())
    {
        $sql = "select id,parentid,name,link,target from mmy_menu where status='".self::STATUS."' and parentid='".$parent_id."';";
        $arr = $this->MenuModel->query($sql);
        foreach ($arr as $cm) {
            $thisArr=&$result[];
            $cm["children"] = $this->getMenuList($cm["id"],$thisArr);
            $thisArr = $cm;
        }
        return $result;

    }

//    protected function getCommlist($parent_id = 0,&$result = array()){
//        $arr = M('comment')->where("parent_id = '".$parent_id."'")->order("create_time desc")->select();
//        if(empty($arr)){
//            return array();
//        }
//        foreach ($arr as $cm) {
//            $thisArr=&$result[];
//            $cm["children"] = $this->getCommlist($cm["id"],$thisArr);
//            $thisArr = $cm;
//        }
//        return $result;
//    }
}

